import _regeneratorRuntime from "@babel/runtime/regenerator";
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";

/**
 * service - SQL执行界面
 * @date: 2018-9-27

 */
import request from 'utils/request';
import { CPAAS_PLATFORM } from 'utils/config';
import { getCurrentOrganizationId } from 'utils/utils';
var organizationId = getCurrentOrganizationId();
/**
 *获取可访问的数据表
 * @returns
 */

export function fetchDataTable(_x) {
  return _fetchDataTable.apply(this, arguments);
}
/**
 *获取数据表的字段值
 * @returns
 */

function _fetchDataTable() {
  _fetchDataTable = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(params) {
    return _regeneratorRuntime.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            return _context.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/db-ide"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  }));
  return _fetchDataTable.apply(this, arguments);
}

export function fetchTableField(_x2) {
  return _fetchTableField.apply(this, arguments);
}
/**
 *获取SQL执行结果
 * @returns
 */

function _fetchTableField() {
  _fetchTableField = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(params) {
    return _regeneratorRuntime.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            return _context2.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/db-ide/field"), {
              method: 'GET',
              query: params
            }));

          case 1:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  }));
  return _fetchTableField.apply(this, arguments);
}

export function fetchExecuteResult(_x3) {
  return _fetchExecuteResult.apply(this, arguments);
}
/**
 *获取单条SQL的翻页结果
 * @returns
 */

function _fetchExecuteResult() {
  _fetchExecuteResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(params) {
    return _regeneratorRuntime.wrap(function _callee3$(_context3) {
      while (1) {
        switch (_context3.prev = _context3.next) {
          case 0:
            return _context3.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/db-ide/sql"), {
              method: 'POST',
              body: {
                sql: params.sql
              },
              query: {
                tenantId: params.tenantId,
                page: params.page,
                size: params.size
              }
            }));

          case 1:
          case "end":
            return _context3.stop();
        }
      }
    }, _callee3);
  }));
  return _fetchExecuteResult.apply(this, arguments);
}

export function fetchSingleResult(_x4) {
  return _fetchSingleResult.apply(this, arguments);
}

function _fetchSingleResult() {
  _fetchSingleResult = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(params) {
    return _regeneratorRuntime.wrap(function _callee4$(_context4) {
      while (1) {
        switch (_context4.prev = _context4.next) {
          case 0:
            return _context4.abrupt("return", request("".concat(CPAAS_PLATFORM, "/v1/").concat(organizationId, "/db-ide/sql/page"), {
              method: 'POST',
              body: {
                sql: params.sql
              },
              query: {
                page: params.page,
                size: params.size
              }
            }));

          case 1:
          case "end":
            return _context4.stop();
        }
      }
    }, _callee4);
  }));
  return _fetchSingleResult.apply(this, arguments);
}